<template>
    <div class="goods-list" >
        <!-- <router-link :to="'/home/goodsinfo/'+item.id" class="goods-item" v-for="item in goodslist" :key="item.id">
            <img :src="item.img_url" alt="" tag="div">
            <h1 class="title">{{ item.title }}</h1>
            <div class="info">
                <p class="price">
                    <span class="now">￥{{ item.sell_price }}</span>
                    <span class="old">￥{{ item.market_price }}</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩{{ item.stock_quantiky}}件</span>
                </p>
            </div>
        </router-link> -->

        <!-- 在网页中有两种跳转方式 -->
        <!-- 方式1：使用a标签 -->
        <!-- 方式2：使用window.location.href的形式 -->
        <div  class="goods-item" v-for="item in goodslist" :key="item.id" @click="goDetail(item.id)">
            <img :src="item.img_url" alt="" >
            <h1 class="title">{{ item.title }}</h1>
            <div class="info">
                <p class="price">
                    <span class="now">￥{{ item.sell_price }}</span>
                    <span class="old">￥{{ item.market_price }}</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩{{ item.stock_quantiky}}件</span>
                </p>
            </div>
        </div>
        <mt-button type="danger" size="large" @click="getMore">加载更多</mt-button>
    </div>
</template>
<script>
import { Toast } from "mint-ui";
    export default {
        data(){
            return{
                pageindex:1,
                goodslist:[]
            }
        },
        created() {
            this.getGoodsList();
        },
        methods:{
            getGoodsList(){
                this.$http
                .get('api/getgoods?pageindex'+this.pageindex)
                .then(result=>{
                if(result.body.status === 0){
                    // this.goodslist = result.body.message;
                    this.goodslist = this.goodslist.concat(result.body.message);
                  }else{
                      Toast('获取失败')
                  }
                });
            },
            getMore(){
                this.pageindex++;
                this.getGoodsList();
            },
            goDetail(id){
            // this.$router.push('/home/goodsinfo/'+id)
            // this.$router.push('/home/goodsinfo/'+id)
            this.$router.push({ name:"goodsinfo",params:{ id }})
            }

        }
    }
</script>
<style scoped>
.goods-list{
    display: flex;
    flex-wrap: wrap;
    padding: 10px;
}
.goods-item{
    width: 45%;
    border: 1px solid #ccc;
    box-shadow: 0 0 8px #ccc;
    margin: 4px 2.5%;
    padding: 2px;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    min-height: 293px;
}
.goods-item img{
    width: 100%;
}
.goods-item .title{
    font-size: 14px;
}
.goods-item .info{
    background-color: #eee;
    
}
.goods-item .info p{
    margin: 0;
    padding: 5px;
}
.goods-item .info .price .now{
    color: red;
    font-weight: bold;
    font-size: 16px;
}
.goods-item .info .price .old{
    text-decoration: line-through;
    font-size: 12px;
    margin-left: 10px;
}
.goods-item .info  .sell{
    font-size: 12px;
    display: flex;
    justify-content: space-between;
}
</style>
